package com.ruoyi.common.core.domain;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.Instant;

/**
 * @ClassName ResponseEntity
 * @Description TODO
 * @Author Mr、Liu
 * @Date 2025/6/25 0:05
 * @Version 1.0
 */

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResponseEntity {

    private int code;
    private String message;
    private Object data;
    private long timestamp;

    /**
     * 成功
     * @param data
     * @return
     */
    public ResponseEntity success(Object data){
        this.code = 200;
        this.message = "操作成功";
        this.data = data;
        this.timestamp = Instant.now().getEpochSecond();
        return this;
    }

    public ResponseEntity error(String message){
        this.code = 500;
        this.message = "失败原因:"+message;
        this.timestamp = Instant.now().getEpochSecond();
        return this;
    }
}
